package com.ajl.wx.module.course.service.impl;

import com.ajl.wx.beans.dto.CourseDTO;
import com.ajl.wx.beans.po.CoursePO;
import com.ajl.wx.module.course.mapper.TbCourseMapper;
import com.ajl.wx.module.course.service.ITbCourseService;
import com.ajl.wx.beans.vo.BaseMap;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HouXinLin
 * @since 2020-09-17
 */
@Service
public class TbCourseServiceImpl extends ServiceImpl<TbCourseMapper, CoursePO> implements ITbCourseService {
    @Autowired
    TbCourseMapper tbCourseMapper;

    @Override
    public int insert(CoursePO coursePO) {
        return tbCourseMapper.insert(coursePO);
    }

    @Override
    public List<String> listTypes() {
        List<CoursePO> distinct_course_type = list(new QueryWrapper<CoursePO>().select("distinct course_type"));
        return  distinct_course_type.stream().map(CoursePO::getCourseType).collect(Collectors.toList());
    }

    @Override
    public  List<CourseDTO> listCourseByType(String type) {
        return tbCourseMapper.listCourseByType(type);
    }

    @Override
    public List<BaseMap> listHot() {
        return tbCourseMapper.listHot();
    }

    @Override
    public List<CoursePO> listCourse() {
        return tbCourseMapper.listCourse();
    }
}
